

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>aiy.leds &mdash; AIY Projects 2018-11-16 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/custom.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="aiy.pins" href="aiy.pins.html" />
    <link rel="prev" title="aiy.board" href="aiy.board.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html" class="icon icon-home"> AIY Projects
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Common APIs</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="aiy.board.html">aiy.board</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">aiy.leds</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.pins.html">aiy.pins</a></li>
</ul>
<p class="caption"><span class="caption-text">Vision Kit APIs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="vision.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.toneplayer.html">aiy.toneplayer</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.trackplayer.html">aiy.trackplayer</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.annotator.html">aiy.vision.annotator</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.inference.html">aiy.vision.inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.models.html">aiy.vision.models</a></li>
</ul>
<p class="caption"><span class="caption-text">Voice Kit APIs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="voice.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.assistant.html">aiy.assistant</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.cloudspeech.html">aiy.cloudspeech</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.voice.audio.html">aiy.voice.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.voice.tts.html">aiy.voice.tts</a></li>
</ul>
<p class="caption"><span class="caption-text">Other docs</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian">Source code (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/CHANGES.md">Change log (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/HACKING.md">Software setup (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/CONTRIBUTING.md">Contribution guide (GitHub)</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">AIY Projects</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>aiy.leds</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/aiy.leds.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="module-aiy.leds">
<span id="aiy-leds"></span><h1>aiy.leds<a class="headerlink" href="#module-aiy.leds" title="Permalink to this headline">¶</a></h1>
<p>APIs to control the RGB LED in the button that connects to the
Vision/Voice Bonnet, and the privacy LED with the Vision Kit.</p>
<p>These APIs are <strong>not compatible</strong> with the Voice HAT (V1 Voice Kit).
To control the Voice HAT’s button LED, instead use <a class="reference internal" href="aiy.board.html#aiy.board.Led" title="aiy.board.Led"><code class="xref py py-class docutils literal notranslate"><span class="pre">aiy.board.Led</span></code></a>.</p>
<p>For example, here’s how to blink the button’s red light:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">aiy.leds</span> <span class="kn">import</span> <span class="n">Leds</span><span class="p">,</span> <span class="n">Color</span>

<span class="k">with</span> <span class="n">Leds</span><span class="p">()</span> <span class="k">as</span> <span class="n">leds</span><span class="p">:</span>
    <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">):</span>
        <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">rgb_on</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">RED</span><span class="p">))</span>
        <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">rgb_off</span><span class="p">())</span>
        <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
</pre></div>
</div>
<p>For more examples, see <a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/src/examples/leds_example.py">leds_example.py</a>.</p>
<p>These APIs are only for the RGB LED in the button and the Vision Kit’s privacy LED.
To control LEDs you’ve attached to the bonnet’s GPIO pins or the LEDs named
<code class="docutils literal notranslate"><span class="pre">LED_1</span></code> and <code class="docutils literal notranslate"><span class="pre">LED_2</span></code> on the Vision/Voice Bonnet, instead use <a class="reference internal" href="aiy.pins.html#module-aiy.pins" title="aiy.pins"><code class="xref py py-mod docutils literal notranslate"><span class="pre">aiy.pins</span></code></a>.</p>
<dl class="class">
<dt id="aiy.leds.Color">
<em class="property">class </em><code class="sig-prename descclassname">aiy.leds.</code><code class="sig-name descname">Color</code><a class="headerlink" href="#aiy.leds.Color" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Defines colors as RGB tuples that can be used as color values with
<a class="reference internal" href="#aiy.leds.Leds" title="aiy.leds.Leds"><code class="xref py py-class docutils literal notranslate"><span class="pre">Leds</span></code></a>.</p>
<dl class="attribute">
<dt id="aiy.leds.Color.BLACK">
<code class="sig-name descname">BLACK</code><em class="property"> = (0, 0, 0)</em><a class="headerlink" href="#aiy.leds.Color.BLACK" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Color.BLUE">
<code class="sig-name descname">BLUE</code><em class="property"> = (0, 0, 255)</em><a class="headerlink" href="#aiy.leds.Color.BLUE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Color.CYAN">
<code class="sig-name descname">CYAN</code><em class="property"> = (0, 255, 255)</em><a class="headerlink" href="#aiy.leds.Color.CYAN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Color.GREEN">
<code class="sig-name descname">GREEN</code><em class="property"> = (0, 255, 0)</em><a class="headerlink" href="#aiy.leds.Color.GREEN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Color.PURPLE">
<code class="sig-name descname">PURPLE</code><em class="property"> = (255, 0, 255)</em><a class="headerlink" href="#aiy.leds.Color.PURPLE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Color.RED">
<code class="sig-name descname">RED</code><em class="property"> = (255, 0, 0)</em><a class="headerlink" href="#aiy.leds.Color.RED" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Color.WHITE">
<code class="sig-name descname">WHITE</code><em class="property"> = (255, 255, 255)</em><a class="headerlink" href="#aiy.leds.Color.WHITE" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Color.YELLOW">
<code class="sig-name descname">YELLOW</code><em class="property"> = (255, 255, 0)</em><a class="headerlink" href="#aiy.leds.Color.YELLOW" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="aiy.leds.Color.blend">
<em class="property">static </em><code class="sig-name descname">blend</code><span class="sig-paren">(</span><em class="sig-param">color_a</em>, <em class="sig-param">color_b</em>, <em class="sig-param">alpha</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Color.blend" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a color that is a blend between two colors.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>color_a</strong> – One of two colors to blend.</p></li>
<li><p><strong>color_b</strong> – One of two colors to blend.</p></li>
<li><p><strong>alpha</strong> – The alpha blend to apply between <code class="docutils literal notranslate"><span class="pre">color_a</span></code> and
<code class="docutils literal notranslate"><span class="pre">color_b</span></code>, from 0.0 to 1.0, respectively. That is,
0.0 makes <code class="docutils literal notranslate"><span class="pre">color_a</span></code> transparent so only <code class="docutils literal notranslate"><span class="pre">color_b</span></code> is
visible; 0.5 blends the two colors evenly; 1.0 makes
<code class="docutils literal notranslate"><span class="pre">color_b</span></code> transparent so  only <code class="docutils literal notranslate"><span class="pre">color_a</span></code> is visible.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>An RGB tuple.</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="aiy.leds.Leds">
<em class="property">class </em><code class="sig-prename descclassname">aiy.leds.</code><code class="sig-name descname">Leds</code><span class="sig-paren">(</span><em class="sig-param">reset=True</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Class to control the KTD LED driver chip in the button used with the
Vision and Voice Bonnet.</p>
<dl class="class">
<dt id="aiy.leds.Leds.Channel">
<em class="property">class </em><code class="sig-name descname">Channel</code><span class="sig-paren">(</span><em class="sig-param">state</em>, <em class="sig-param">brightness</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.Channel" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Defines the configuration for each channel in the KTD LED driver.</p>
<p>You should not instantiate this class directly; instead create a
dictionary of <code class="docutils literal notranslate"><span class="pre">Channel</span></code> objects with the other methods below,
which you can then pass to <a class="reference internal" href="#aiy.leds.Leds.update" title="aiy.leds.Leds.update"><code class="xref py py-meth docutils literal notranslate"><span class="pre">update()</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>state</strong> – Either <a class="reference internal" href="#aiy.leds.Leds.Channel.ON" title="aiy.leds.Leds.Channel.ON"><code class="xref py py-attr docutils literal notranslate"><span class="pre">ON</span></code></a>, <a class="reference internal" href="#aiy.leds.Leds.Channel.OFF" title="aiy.leds.Leds.Channel.OFF"><code class="xref py py-attr docutils literal notranslate"><span class="pre">OFF</span></code></a>, or
<a class="reference internal" href="#aiy.leds.Leds.Channel.PATTERN" title="aiy.leds.Leds.Channel.PATTERN"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PATTERN</span></code></a>.</p></li>
<li><p><strong>brightness</strong> – A value between 0 and 255.</p></li>
</ul>
</dd>
</dl>
<dl class="attribute">
<dt id="aiy.leds.Leds.Channel.OFF">
<code class="sig-name descname">OFF</code><em class="property"> = 0</em><a class="headerlink" href="#aiy.leds.Leds.Channel.OFF" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Leds.Channel.ON">
<code class="sig-name descname">ON</code><em class="property"> = 1</em><a class="headerlink" href="#aiy.leds.Leds.Channel.ON" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="aiy.leds.Leds.Channel.PATTERN">
<code class="sig-name descname">PATTERN</code><em class="property"> = 2</em><a class="headerlink" href="#aiy.leds.Leds.Channel.PATTERN" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.installed">
<em class="property">static </em><code class="sig-name descname">installed</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.installed" title="Permalink to this definition">¶</a></dt>
<dd><p>Internal method to verify the <code class="docutils literal notranslate"><span class="pre">Leds</span></code> class is available.</p>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.pattern">
<em class="property">property </em><code class="sig-name descname">pattern</code><a class="headerlink" href="#aiy.leds.Leds.pattern" title="Permalink to this definition">¶</a></dt>
<dd><p>Defines a blink pattern for the button’s LED. Must be set with a
<a class="reference internal" href="#aiy.leds.Pattern" title="aiy.leds.Pattern"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pattern</span></code></a> object. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">Leds</span><span class="p">()</span> <span class="k">as</span> <span class="n">leds</span><span class="p">:</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">pattern</span> <span class="o">=</span> <span class="n">Pattern</span><span class="o">.</span><span class="n">blink</span><span class="p">(</span><span class="mi">500</span><span class="p">)</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">rgb_pattern</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">RED</span><span class="p">))</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.privacy">
<em class="property">static </em><code class="sig-name descname">privacy</code><span class="sig-paren">(</span><em class="sig-param">enabled</em>, <em class="sig-param">brightness=255</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.privacy" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a configuration for the privacy LED (channel 4).</p>
<p>You can instead use <a class="reference internal" href="#aiy.leds.Leds.privacy_on" title="aiy.leds.Leds.privacy_on"><code class="xref py py-meth docutils literal notranslate"><span class="pre">privacy_on()</span></code></a> and <a class="reference internal" href="#aiy.leds.Leds.privacy_off" title="aiy.leds.Leds.privacy_off"><code class="xref py py-meth docutils literal notranslate"><span class="pre">privacy_off()</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>enabled</strong> – <code class="docutils literal notranslate"><span class="pre">True</span></code> to turn on the light; <code class="docutils literal notranslate"><span class="pre">False</span></code> to turn it off.</p></li>
<li><p><strong>brightness</strong> – A value from 0 to 255.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A dictionary with one <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> for the privacy LED
(channel 4).</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.privacy_off">
<em class="property">static </em><code class="sig-name descname">privacy_off</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.privacy_off" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an “off” configuration for the privacy LED
(the front LED on the Vision Kit).</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>A dictionary with one <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> for the privacy LED
(channel 4).</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.privacy_on">
<em class="property">static </em><code class="sig-name descname">privacy_on</code><span class="sig-paren">(</span><em class="sig-param">brightness=255</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.privacy_on" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an “on” configuration for the privacy LED
(the front LED on the Vision Kit).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>brightness</strong> – A value from 0 to 255.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A dictionary with one <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> for the privacy LED
(channel 4).</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.reset">
<code class="sig-name descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.reset" title="Permalink to this definition">¶</a></dt>
<dd><p>Resets the LED driver to a clean state.</p>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.rgb">
<em class="property">static </em><code class="sig-name descname">rgb</code><span class="sig-paren">(</span><em class="sig-param">state</em>, <em class="sig-param">rgb</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.rgb" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a configuration for the RGB channels: 1 (red), 2 (green), 3 (blue).</p>
<p>Generally, you should instead use convenience constructors such as
<a class="reference internal" href="#aiy.leds.Leds.rgb_on" title="aiy.leds.Leds.rgb_on"><code class="xref py py-func docutils literal notranslate"><span class="pre">rgb_on()</span></code></a> and <a class="reference internal" href="#aiy.leds.Leds.rgb_pattern" title="aiy.leds.Leds.rgb_pattern"><code class="xref py py-func docutils literal notranslate"><span class="pre">rgb_pattern()</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>state</strong> – Either <a class="reference internal" href="#aiy.leds.Leds.Channel.ON" title="aiy.leds.Leds.Channel.ON"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Channel.ON</span></code></a>, <a class="reference internal" href="#aiy.leds.Leds.Channel.OFF" title="aiy.leds.Leds.Channel.OFF"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Channel.OFF</span></code></a>, or
<a class="reference internal" href="#aiy.leds.Leds.Channel.PATTERN" title="aiy.leds.Leds.Channel.PATTERN"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Channel.PATTERN</span></code></a>.</p></li>
<li><p><strong>rgb</strong> – Either one of the <a class="reference internal" href="#aiy.leds.Color" title="aiy.leds.Color"><code class="xref py py-class docutils literal notranslate"><span class="pre">Color</span></code></a> constants or your own tuple
of RGB values.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A dictionary of 3 <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> objects, representing red, green,
and blue values.</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.rgb_off">
<em class="property">static </em><code class="sig-name descname">rgb_off</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.rgb_off" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an “off” configuration for the button’s RGB LED.</p>
<dl class="field-list simple">
<dt class="field-odd">Returns</dt>
<dd class="field-odd"><p>A dictionary of 3 <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> objects, representing red,
green, and blue values, all turned off.</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.rgb_on">
<em class="property">static </em><code class="sig-name descname">rgb_on</code><span class="sig-paren">(</span><em class="sig-param">rgb</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.rgb_on" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates an “on” configuration for the button’s RGB LED.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rgb</strong> – Either one of the <a class="reference internal" href="#aiy.leds.Color" title="aiy.leds.Color"><code class="xref py py-class docutils literal notranslate"><span class="pre">Color</span></code></a> constants or your own tuple
of RGB values.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A dictionary of 3 <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> objects, representing red,
green, and blue values.</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.rgb_pattern">
<em class="property">static </em><code class="sig-name descname">rgb_pattern</code><span class="sig-paren">(</span><em class="sig-param">rgb</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.rgb_pattern" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates a “pattern” configuration for the button’s RGB LED, using
the light pattern set with <a class="reference internal" href="#aiy.leds.Leds.pattern" title="aiy.leds.Leds.pattern"><code class="xref py py-attr docutils literal notranslate"><span class="pre">pattern</span></code></a> and the color set here.
For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">Leds</span><span class="p">()</span> <span class="k">as</span> <span class="n">leds</span><span class="p">:</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">pattern</span> <span class="o">=</span> <span class="n">Pattern</span><span class="o">.</span><span class="n">blink</span><span class="p">(</span><span class="mi">500</span><span class="p">)</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">rgb_pattern</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">RED</span><span class="p">))</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>rgb</strong> – Either one of the <a class="reference internal" href="#aiy.leds.Color" title="aiy.leds.Color"><code class="xref py py-class docutils literal notranslate"><span class="pre">Color</span></code></a> constants or your own tuple
of RGB values.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A dictionary of 3 <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> objects, representing red,
green, and blue values.</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Leds.update">
<code class="sig-name descname">update</code><span class="sig-paren">(</span><em class="sig-param">channels</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Leds.update" title="Permalink to this definition">¶</a></dt>
<dd><p>Changes the state of an LED. Takes a dictionary of LED channel
configurations, provided by various methods such as
<a class="reference internal" href="#aiy.leds.Leds.rgb_on" title="aiy.leds.Leds.rgb_on"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rgb_on()</span></code></a>, <a class="reference internal" href="#aiy.leds.Leds.rgb_off" title="aiy.leds.Leds.rgb_off"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rgb_off()</span></code></a>, and <a class="reference internal" href="#aiy.leds.Leds.rgb_pattern" title="aiy.leds.Leds.rgb_pattern"><code class="xref py py-meth docutils literal notranslate"><span class="pre">rgb_pattern()</span></code></a>.</p>
<p>For example, turn on the red light:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">Leds</span><span class="p">()</span> <span class="k">as</span> <span class="n">leds</span><span class="p">:</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">rgb_on</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">RED</span><span class="p">))</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">rgb_off</span><span class="p">())</span>
</pre></div>
</div>
<p>Or turn on the privacy LED (Vision Kit only):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">Leds</span><span class="p">()</span> <span class="k">as</span> <span class="n">leds</span><span class="p">:</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">privacy_on</span><span class="p">())</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
    <span class="n">leds</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">Leds</span><span class="o">.</span><span class="n">privacy_off</span><span class="p">())</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>channels</strong> – A dictionary of one or more <a class="reference internal" href="#aiy.leds.Leds.Channel" title="aiy.leds.Leds.Channel"><code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code></a> objects.
Use the <code class="docutils literal notranslate"><span class="pre">rgb_</span></code> and <code class="docutils literal notranslate"><span class="pre">privacy_</span></code> methods to create a
dictionary.</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="aiy.leds.Pattern">
<em class="property">class </em><code class="sig-prename descclassname">aiy.leds.</code><code class="sig-name descname">Pattern</code><span class="sig-paren">(</span><em class="sig-param">period_ms</em>, <em class="sig-param">on_percent=0.5</em>, <em class="sig-param">rise_ms=0</em>, <em class="sig-param">fall_ms=0</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Pattern" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Defines an LED blinking pattern. Pass an instance of this to
<a class="reference internal" href="#aiy.leds.Leds.pattern" title="aiy.leds.Leds.pattern"><code class="xref py py-attr docutils literal notranslate"><span class="pre">Leds.pattern</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>period_ms</strong> – The period of time (in milliseconds) for each on/off
sequence.</p></li>
<li><p><strong>on_percent</strong> – Percent of time during the period to turn on the LED
(the LED turns on at the beginning of the period).</p></li>
<li><p><strong>rise_ms</strong> – Duration of time to fade the light on.</p></li>
<li><p><strong>fall_ms</strong> – Duration of time to fade the light off.</p></li>
</ul>
</dd>
</dl>
<p>The parameters behave as illustrated below.</p>
<div class="highlight-text notranslate"><div class="highlight"><pre><span></span>rise_ms /----------\ fall_ms
       /            \
      /  on_percent  \
     #--------------------------------#
                  period_ms
</pre></div>
</div>
<dl class="method">
<dt id="aiy.leds.Pattern.blink">
<em class="property">static </em><code class="sig-name descname">blink</code><span class="sig-paren">(</span><em class="sig-param">period_ms</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Pattern.blink" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience method to create a blinking pattern.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>period_ms</strong> – The period of time (in milliseconds) for each on/off
sequence.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A <a class="reference internal" href="#aiy.leds.Pattern" title="aiy.leds.Pattern"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pattern</span></code></a>.</p>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.leds.Pattern.breathe">
<em class="property">static </em><code class="sig-name descname">breathe</code><span class="sig-paren">(</span><em class="sig-param">period_ms</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.Pattern.breathe" title="Permalink to this definition">¶</a></dt>
<dd><p>Convenience method to create a breathing pattern (a blink that fades
in and out).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>period_ms</strong> – The period of time (in milliseconds) for each on/off
sequence.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A <a class="reference internal" href="#aiy.leds.Pattern" title="aiy.leds.Pattern"><code class="xref py py-class docutils literal notranslate"><span class="pre">Pattern</span></code></a>.</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="aiy.leds.PrivacyLed">
<em class="property">class </em><code class="sig-prename descclassname">aiy.leds.</code><code class="sig-name descname">PrivacyLed</code><span class="sig-paren">(</span><em class="sig-param">leds</em>, <em class="sig-param">brightness=32</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.PrivacyLed" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Helper class to turn Privacy LED off automatically.</p>
<p>When instantiated, the privacy LED turns on. It turns off whenever
the code exits the scope in which this was created. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Turn the privacy LED on for 2 seconds</span>
<span class="k">with</span> <span class="n">PrivacyLed</span><span class="p">(</span><span class="n">Leds</span><span class="p">()):</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>leds</strong> – An instance of <a class="reference internal" href="#aiy.leds.Leds" title="aiy.leds.Leds"><code class="xref py py-class docutils literal notranslate"><span class="pre">Leds</span></code></a>.</p></li>
<li><p><strong>brightness</strong> – A value between 0 and 255.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="class">
<dt id="aiy.leds.RgbLeds">
<em class="property">class </em><code class="sig-prename descclassname">aiy.leds.</code><code class="sig-name descname">RgbLeds</code><span class="sig-paren">(</span><em class="sig-param">leds</em>, <em class="sig-param">channels</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.leds.RgbLeds" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<p>Helper class to turn RGB LEDs off automatically.</p>
<p>When instantiated, the privacy LED turns on. It turns off whenever
the code exits the scope in which this was created. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Turn on the green LED for 2 seconds</span>
<span class="k">with</span> <span class="n">RgbLeds</span><span class="p">(</span><span class="n">Leds</span><span class="p">(),</span> <span class="n">Leds</span><span class="o">.</span><span class="n">rgb_on</span><span class="p">(</span><span class="n">Color</span><span class="o">.</span><span class="n">GREEN</span><span class="p">)):</span>
    <span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>leds</strong> – An instance of <a class="reference internal" href="#aiy.leds.Leds" title="aiy.leds.Leds"><code class="xref py py-class docutils literal notranslate"><span class="pre">Leds</span></code></a>.</p></li>
<li><p><strong>channels</strong> – A dictionary of one or more <code class="xref py py-class docutils literal notranslate"><span class="pre">Channel</span></code> objects.
Use the <code class="docutils literal notranslate"><span class="pre">Leds.rgb_</span></code> and <code class="docutils literal notranslate"><span class="pre">Leds.privacy_</span></code> methods to create a
dictionary.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="aiy.pins.html" class="btn btn-neutral float-right" title="aiy.pins" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="aiy.board.html" class="btn btn-neutral float-left" title="aiy.board" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Google LLC

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>